(function($){
    var utils = {};

    utils.setViewStackCurrentElem = function($viewStackElems,index){
        $viewStackElems.each(function(i, domElem){
            var fucName = i === index ? "addClass" : "removeClass";
            $(domElem)[fucName]("current");
        });
    };

//TabController:使用该类可以给标签页栏增加控制.viewStackElem样式面板的功能
//tabBar:包含标签页按钮的容器
//viewStack:包含.viewStackElem样式面板的容器
//tabBtnStyle:标签页按钮的样式
    function TabController(tabBar,viewStack,tabBtnStyle){
        var self = this;
        self.$tabBtns = $(tabBar).children(tabBtnStyle);
        self.$viewStackElems = $(viewStack).children(".viewStackElem");

        self.$tabBtns.each(function(i, domElem){
            $(domElem).click(function(){
                self.setSelectedTab(i);
            });
        });
    };

    TabController.prototype.setSelectedTab = function(index){
        this.$tabBtns.each(function(i, domElem){
            var fucName = i === index ? "addClass" : "removeClass";
            $(domElem)[fucName]("current");
        });
        utils.setViewStackCurrentElem(this.$viewStackElems, index);
    };

    utils.TabController = TabController;
//

    window.utils = utils;
})(jQuery);